import java.util.Arrays;
import java.util.PriorityQueue;

/**
* @description: 973. 最接近原点的 K 个点
* @author hewei
* @date 2022/10/4 16:16
* @version 1.0
*/

public class KClosest {

    public int[][] kClosest(int[][] points, int k) {
        PriorityQueue<int[]> heap = new PriorityQueue<>((a, b) -> {
            long temp1 = (long) a[0] * a[0] + (long) a[1] * a[1];
            long temp2 = (long) b[0] * b[0] + (long) b[1] * b[1];
            return Long.compare(temp1, temp2);
        });
        heap.addAll(Arrays.asList(points));
        int[][] ans = new int[k][2];
        for (int i = 0; i < ans.length; i++) {
            ans[i] = heap.poll();
        }
        return ans;
    }
}
